package com.yuzhitong.shapi.widget;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.yuzhitong.shapi.R;

/**
 * Created by Brsya
 * CreateDate: 2022/4/19  16:30
 * Description:
 * 反馈建议弹框
 */
public class FeedbackDialog extends CenterDialog implements View.OnClickListener {
    private Context context;
    private View rootView;
    private EditText etFeedback;
    private TextView textCancel;
    private TextView textConfirm;


    private OnClickBtnListener onClickBtnListener;

    public FeedbackDialog(Context context) {
        super(context);
        this.context = context;

        setContentView(rootView = LayoutInflater.from(context).inflate(R.layout.dialog_feedback, null, false));

        initView();
        setKeyListener(false);
    }

    private void initView() {

        textCancel = (TextView) rootView.findViewById(R.id.text_cancel);
        textConfirm = (TextView) rootView.findViewById(R.id.text_confirm);
        etFeedback = (EditText) rootView.findViewById(R.id.et_feedback);

        textCancel.setOnClickListener(this);
        textConfirm.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.text_cancel) {
            dismiss();
            if (onClickBtnListener != null) {
                onClickBtnListener.onDismiss();
            }
        } else if (id == R.id.text_confirm) {
            String feedback = etFeedback.getText().toString();
            if (feedback.length() == 0) {
                Toast.makeText(context, "没有输入内容", Toast.LENGTH_SHORT).show();
                return;
            }
            if (onClickBtnListener != null) {
                onClickBtnListener.onConfirm(feedback);
            }
        }
    }

    @Override
    public void show() {
        super.show();
        etFeedback.setText("");
    }

    public void setOnClickBtnListener(OnClickBtnListener onClickBtnListener) {
        this.onClickBtnListener = onClickBtnListener;
    }

    public interface OnClickBtnListener {
        void onDismiss();

        void onConfirm(String feedback);
    }
}
